package com.xiaoshuidi.cloud.module.member.controller.admin.mobilemodifyrecord;


import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.framework.excel.core.util.ExcelUtils;
import com.xiaoshuidi.cloud.module.member.controller.admin.mobilemodifyrecord.vo.MemberMobileModifyRecordExportVO;
import com.xiaoshuidi.cloud.module.member.controller.admin.mobilemodifyrecord.vo.MemberMobileModifyRecordPageReqVO;
import com.xiaoshuidi.cloud.module.member.controller.admin.mobilemodifyrecord.vo.MemberMobileModifyRecordPageRespVO;
import com.xiaoshuidi.cloud.module.member.convert.mobilemodifyrecord.MobileModifyRecordConvert;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.service.mobilemodifyrecord.MemberMobileModifyRecordService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 手机号修改记录 前端控制器
 * </p>
 *
 * @author hans.zhang
 * @since 2023-12-08
 */
@Slf4j
@RestController
@RequestMapping(ApiConstants.NAME + "/member-mobile-modify-record")
public class MemberMobileModifyRecordController {

    @Resource
    private MemberMobileModifyRecordService memberMobileModifyRecordService;


    @GetMapping("/page")
    @Operation(summary = "分页")
    //@PreAuthorize("@ss.hasPermission('member:member-mobile-modify-record:query')")
    public CommonResult<PageResult<MemberMobileModifyRecordPageRespVO>> getPage(MemberMobileModifyRecordPageReqVO reqVO){
        return CommonResult.success(memberMobileModifyRecordService.getPage(reqVO));
    }

    @GetMapping("/export")
    @Operation(summary = "导出")
    //@PreAuthorize("@ss.hasPermission('member:member-mobile-modify-record:export')")
    public void export(MemberMobileModifyRecordPageReqVO reqVO, HttpServletResponse response) throws IOException {
        List<MemberMobileModifyRecordPageRespVO> respVOS = memberMobileModifyRecordService.exportList(reqVO);
        List<MemberMobileModifyRecordExportVO> datas =  MobileModifyRecordConvert.INSTANCE.convertList2(respVOS);
        ExcelUtils.write(response, "手机号修改记录.xls", "数据", MemberMobileModifyRecordExportVO.class, datas);
    }
}
